package ioperation;

import book.Book;
import book.BookList;

import java.util.Scanner;

public class DelOperation implements IOPeration{
    public void work(BookList bookList){
        System.out.println("删除图书....");
        Scanner scanner=new Scanner(System.in);
        System.out.println("请输入你要删除的书：");
        String name=scanner.nextLine();
        int currentsize= bookList.getUseSize();
        int pos=0;
        int c = 0;
        for (; c < currentsize; c++) {
            Book book=bookList.getBooks(c);
            if(book.getName().equals(name)){
                pos=c;
                break;
            }
        }
       if(c==currentsize){
           System.out.println("没有你要删除的书");
           return;
       }
        for (int i = pos; i <currentsize-1 ; i++) {
            Book book=bookList.getBooks(i+1);
            bookList.setBooks(i,book);
        }
        System.out.println("删除成功");
        bookList.setUseSize(currentsize-1);
    }
}
